﻿using System.Windows;
using System.Windows.Controls;
using UIT.ScrumTool.Client.Controller;
using UIT.ScrumTool.Client.Utilities.UserGridView;
using Xceed.Wpf.DataGrid;

namespace UIT.ScrumTool.Client.View.Admin
{
    /// <summary>
    /// Interaction logic for uctrlUsers.xaml
    /// </summary>
    public partial class uctrlUsers : UserControl
    {
        public static UserBindingListComplete userBindingListComplete = new UserBindingListComplete();
        public int x, y;

        public uctrlUsers()
        {
            InitializeComponent();
        }

        private void grid_InitializingInsertionRow(object sender, InitializingInsertionRowEventArgs e)
        {
            x = grid.Items.Count;
            y = userBindingListComplete.Count;
        }

        private void grid_SelectionChanged(object sender, DataGridSelectionChangedEventArgs e)
        {
        }

        private void grid_Loaded(object sender, RoutedEventArgs e)
        {
            UserCtrl.UserTable(userBindingListComplete);
            
        }

        private void grid_CurrentChanging(object sender, DataGridCurrentChangingEventArgs e)
        {
            if (y > x)
            {
                try
                {
                    UserEditTable userEditTable = userBindingListComplete.m_lastAddedComposer;
                    string soSanh = userEditTable.LoginName;
                    if (!string.IsNullOrEmpty(soSanh))
                    {
                        UserCtrl.UserInsert(userEditTable);
                        userBindingListComplete.m_lastAddedComposer = null;
                        UserCtrl.UserTable(userBindingListComplete);
                        x = y = 0;
                    }
                }
                catch
                {
                }
            }
        }
    }
}